package com.wms.oms.controller;

import com.wms.common.core.web.controller.BaseController;
import com.wms.common.core.web.domain.AjaxResult;
import com.wms.common.core.web.page.TableDataInfo;
import com.wms.common.security.annotation.PreAuthorize;
import com.wms.oms.domain.CheckOrder;
import com.wms.oms.service.ICheckOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * @author zzm
 * @date 2023/8/18
 * @desc
 */
@RestController
@RequestMapping("/check")
public class CheckOrderController extends BaseController {


    @Autowired
    private ICheckOrderService checkOrderService;

    /**
     * 查询盘点单列表
     */
    @PreAuthorize(hasPermi = "oms:checkOrder:list")
    @GetMapping("/list")
    public TableDataInfo list(CheckOrder checkOrder)
    {
        startPage();
        List<CheckOrder> list = checkOrderService.selectCheckOrderList(checkOrder);
        return getDataTable(list);
    }


    /**
     * 获取盘点单详细信息
     */
    @PreAuthorize(hasPermi = "oms:checkOrder:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        CheckOrder checkOrder =  checkOrderService.selectCheckOrderById(id);
        return AjaxResult.success(checkOrder);
    }


    /**
     * 新增盘点单
     */
    @PreAuthorize(hasPermi = "oms:checkOrder:add")
    @PostMapping(value = "save")
    public AjaxResult add(@RequestBody @Valid CheckOrder checkOrder)
    {
        return toAjax(checkOrderService.insertCheckOrder(checkOrder));
    }


    /**
     * 修改盘点单
     */
    @PreAuthorize(hasPermi = "oms:checkOrder:edit")
    @PostMapping(value = "update")
    public AjaxResult edit(@RequestBody @Valid CheckOrder checkOrder)
    {
        return toAjax(checkOrderService.updateCheckOrder(checkOrder));
    }


    /**
     * 盘点确认
     */
    @PreAuthorize(hasPermi = "oms:checkOrder:edit")
    @PostMapping(value = "confirm/{id}")
    public AjaxResult confirm(@PathVariable("id") Long id)
    {
        CheckOrder checkOrder = checkOrderService.selectCheckOrderById(id);
        return toAjax(checkOrderService.confirm(checkOrder));
    }


    /**
     * 删除盘点单
     */
    @PreAuthorize(hasPermi = "oms:checkOrder:remove")
    @PostMapping(value = "delete/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(checkOrderService.deleteCheckOrderByIds(ids));
    }

}
